package com.project.controller.customer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("customer/order")
@RestController
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @RequestMapping("addOrder")
    public String addOrder(OrderBean order, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        orderService.add(order,user.getId());
        return "ok";
    }

    @RequestMapping("findAll")
    public IPage<OrderBean> findAll(int pageNO, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return orderService.findAll(pageNO,user.getId());
    }

    @RequestMapping("findById")
    public OrderBean findById(int orderId){
        return orderService.findById(orderId);
    }
}
